package com.taotao.web.controller;

import com.taotao.entity.Item;
import com.taotao.service.RestItemService;
import com.taotao.vo.ResultVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * author: 王明跃
 * Create at: 18/7/6下午2:31
 */
@Controller
@RequestMapping("/rest/item")
public class RestItemController {
    @Resource
    private RestItemService restItemService;

    // 删除
    @ResponseBody
    @RequestMapping("/delete")
    public ResultVO delete(Long[] ids) {
        ResultVO resultVO = restItemService.delete(ids);
        String message = Cross.deleteIds(Cross.DURL, ids);
        System.out.println(message);
        resultVO.setMessage(message);
        return resultVO;
    }

    // 下架
    @ResponseBody
    @RequestMapping("/instock")
    public ResultVO updateDown(Long[] ids) {
        int i = restItemService.updateDown(ids);
        ResultVO resultVO = new ResultVO();
        if (i > 0) {
            resultVO.setStatus(200);
            String message = Cross.deleteIds(Cross.DURL, ids);
            System.out.println(message);
            resultVO.setMessage(message);
        }
        return resultVO;
    }

    // 上架
    @ResponseBody
    @RequestMapping("/reshelf")
    public ResultVO updateUp(Long[] ids) {
        int i = restItemService.updateUp(ids);
        ResultVO resultVO = new ResultVO();
        if (i > 0) {
            resultVO.setStatus(200);
            String message = Cross.deleteIds(Cross.UURL, ids);
            System.out.println(message);
            resultVO.setMessage(message);
        }
        return resultVO;
    }

    // 修改商品信息
    @RequestMapping("/update")
    @ResponseBody
    public ResultVO updateItem(Item item, String desc) {
        ResultVO resultVO = restItemService.updateItem(item, desc);
        String message = Cross.deleteIds(Cross.UURL, new Long[]{item.getId()});
        System.out.println(message);
        resultVO.setMessage(message);
        return resultVO;
    }
}
